package org.pf.base.pfBlocks
{
	import flash.display.Sprite;
	import org.farmcode.bezier.Path;
	import org.pf.base.PFBlock;
	import org.pf.base.pfGraphics.staff.DrawBitmap;
	import org.pf.base.pfStorages.PFStorageBodySprites;
	import org.pf.base.pfStorages.PFStorageImages;
	import org.pf.constructor.staff.PFBodyGeometry;
	import org.pf.interfaces.IPFCache;
	import org.pf.semaphore.PFCommonSemaphore;
	
	/**
	 * ...
	 * @author zeksa'
	 */
	public class PFCache extends PFBlock implements IPFCache
	{
		private var _levelsList:Array;
		private var _currentLevel:PFLevel;
		
		private var _sprites:PFStorageBodySprites;
		private var _images:PFStorageImages;
		
		private var _ropes:Array = new Array();
		private var _ropesNames:Array = new Array();
		private var _ropesBodies:Array = new Array();
		
		private var _particlesList:Array = new Array();
		
		private var _enabledAnimations:Array;
		private var _changeAnimationStateSemaphore:PFCommonSemaphore;
		
		private var _bezierPath:Path = new Path();
		
		private var _nextState:Class;
		
		public function PFCache()
		{
			super(PFBlock.CACHE_BLOCK);
			("created Cache.as class object");
			_enabledAnimations = new Array();
			_changeAnimationStateSemaphore = new PFCommonSemaphore();
		}
		
		override public function activate():void
		{
			/*PFPrince.getPrince().get_SystemCache().layers.viewLayer = null;
			PFPrince.getPrince().get_SystemCache().effectsLayer = null;
			PFPrince.getPrince().get_SystemCache().layers.viewLayer = new Sprite();
			PFPrince.getPrince().get_SystemCache().effectsLayer = new Sprite();
			PFPrince.getPrince().get_SystemCache().layers.addChild(PFPrince.getPrince().get_SystemCache().layers.viewLayer)
			PFPrince.getPrince().get_SystemCache().layers.addChild(PFPrince.getPrince().get_SystemCache().effectsLayer);*/
		}
		
		override public function deactivate():void
		{
//			PFPrince.getPrince().get_SystemCache().stage.removeChild(PFPrince.getPrince().get_SystemCache().currentContainer);
			//PFPrince.getPrince().get_SystemCache().currentContainer = null;
			//TODO: removes currrentContainer there
		}
		
		protected function setLevelList(levels:Array):void
		{
			_levelsList = levels;
		}
		
		public function getLevel(levelName:String):PFLevel
		{
			var tmp:PFLevel;
			for (var i:int = 0; i < _levelsList.length; i++)
			{
				if (_levelsList[i]._name == levelName)
				{
					tmp = _levelsList[i];
					break;
				}
			}
			return tmp;
		}
		
		public function setCurrentLevel(lev:PFLevel):void
		{
			_currentLevel = lev;
		}
		
		protected function setPFBodyGraphicsCollection(sprites:PFStorageBodySprites):void
		{
			_sprites = sprites;
		}
		
		protected function setImagesCollection(images:PFStorageImages):void
		{
			_images = images;
		}
		
		public function get_sprite(bodyGeom:PFBodyGeometry):Sprite
		{
			var sprite:Sprite = DrawBitmap.MakeImageForBody(bodyGeom, _sprites);
			return sprite;
		}
		
		public function getImage(imgName:String):Sprite
		{
			var sprite:Sprite = new Sprite();
			sprite.addChild(_images.getImage(imgName));
			return sprite;	
		}
		
		public function get levelsList():Array
		{
			return _levelsList;
		}
		
		public function get sprites():PFStorageBodySprites
		{
			return _sprites;
		}
		
		public function get ropes():Array
		{
			return _ropes;
		}
		
		public function set ropes(value:Array):void
		{
			_ropes = value;
		}
		
		public function get ropesNames():Array
		{
			return _ropesNames;
		}
		
		public function set ropesNames(value:Array):void
		{
			_ropesNames = value;
		}
		
		public function get ropesBodies():Array
		{
			return _ropesBodies;
		}
		
		public function set ropesBodies(value:Array):void
		{
			_ropesBodies = value;
		}
		
		public function get bezierPath():Path
		{
			return _bezierPath;
		}
		
		public function set bezierPath(value:Path):void
		{
			_bezierPath = value;
		}
		
		public function get particlesList():Array
		{
			return _particlesList;
		}
		
		public function set particlesList(value:Array):void
		{
			_particlesList = value;
		}
		
		public function get nextState():Class
		{
			return _nextState;
		}
		
		public function set nextState(value:Class):void
		{
			_nextState = value;
		}
		
		public function get images():PFStorageImages
		{
			return _images;
		}
		
		public function get currentLevel():PFLevel 
		{
			return _currentLevel;
		}
		
		public function get enabledAnimations():Array 
		{
			return _enabledAnimations;
		}
		
		public function set enabledAnimations(value:Array):void 
		{
			_enabledAnimations = value;
		}
		
		public function get changeAnimationStateSemaphore():PFCommonSemaphore 
		{
			return _changeAnimationStateSemaphore;
		}
		
		public function set changeAnimationStateSemaphore(value:PFCommonSemaphore):void 
		{
			_changeAnimationStateSemaphore = value;
		}
	
	}

}